home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / misc / sci / ephem_src_4_28.lha / mainmenu.c < prev    next >
C/C++ Source or Header  |  1992-04-17  |  6KB  |  264 lines

  1. /* printing routines for the main (upper) screen.
  2.  */
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6. #include "astro.h"
  7. #include "circum.h"
  8. #include "screen.h"
  9.  
  10. /* #define PC_GRAPHICS */
  11. #ifdef PC_GRAPHICS
  12. #define    JOINT    207
  13. #define    VERT    179
  14. #define    HORIZ    205
  15. #else
  16. #define    JOINT    '-'
  17. #define    VERT    '|'
  18. #define    HORIZ    '-'
  19. #endif
  20.  
  21. mm_borders()
  22. {
  23.     char line[NC+1], *lp;
  24.     register i;
  25.  
  26.     lp = line;
  27.     for (i = 0; i < NC; i++)
  28.         *lp++ = HORIZ;
  29.     *lp = '\0';
  30.     f_string (R_PLANTAB-1, 1, line);
  31.     for (i = R_TOP; i < R_PLANTAB-1; i++)
  32.         f_char (i, COL2-2, VERT);
  33.     f_char (R_PLANTAB-1, COL2-2, JOINT);
  34.     for (i = R_TOP; i < R_PLANTAB-1; i++)
  35.         f_char (i, COL3-2, VERT);
  36.     f_char (R_PLANTAB-1, COL3-2, JOINT);
  37.     for (i = R_LST; i < R_PLANTAB-1; i++)
  38.         f_char (i, COL4-2, VERT);
  39.     f_char (R_PLANTAB-1, COL4-2, JOINT);
  40. }
  41.  
  42. /* print the permanent labels on the top menu */
  43. mm_labels()
  44. {
  45.     f_string (R_TZN,    C_TZN,        "LT");
  46.     f_string (R_UT,        C_UT,        "UTC");
  47.     f_string (R_JD,        C_JD,        "JulianDate");
  48.     f_string (R_LISTING,    C_LISTING,    "Listing");
  49.     f_string (R_WATCH,    C_WATCH,    "Watch");
  50.     f_string (R_SRCH,    C_SRCH,        "Search");
  51.     f_string (R_PLOT,    C_PLOT,        "Plot");
  52.     f_string (R_ALTM,    C_ALTM,        "Menu");
  53.  
  54.     f_string (R_LST,    C_LST,        "LST");
  55.     f_string (R_DAWN,    C_DAWN,        "Dawn");
  56.     f_string (R_DUSK,    C_DUSK,        "Dusk");
  57.     f_string (R_LON,    C_LON,        "NiteLn");
  58.     f_string (R_PAUSE,    C_PAUSE,    "Pause");
  59.     f_string (R_NSTEP,    C_NSTEP,    "NStep");
  60.     f_string (R_STPSZ,    C_STPSZ,    "StpSz");
  61.  
  62.     f_string (R_LAT,    C_LAT,        "Lat");
  63.     f_string (R_LONG,    C_LONG,        "Long");
  64.     f_string (R_HEIGHT,    C_HEIGHT,    "Elev");
  65.     f_string (R_TEMP,    C_TEMP,        "Temp");
  66.     f_string (R_PRES,    C_PRES,        "AtmPr");
  67.     f_string (R_TZONE,    C_TZONE,    "TZ");
  68.     f_string (R_EPOCH,    C_EPOCH,    "Epoch");
  69. }
  70.  
  71. /* print all the time/date/where related stuff: the Now structure.
  72.  * print in a nice order, based on the field locations, as much as possible.
  73.  */
  74. mm_now (np, all)
  75. Now *np;
  76. int all;
  77. {
  78.     char buf[32];
  79.     double lmjd = mjd - tz/24.0;
  80.     double jd = mjd + 2415020L;
  81.     double tmp;
  82.  
  83.     (void) sprintf (buf, "%-3.3s", tznm);
  84.     f_string (R_TZN, C_TZN, buf);
  85.     f_time (R_LT, C_LT, mjd_hr(lmjd));
  86.     f_date (R_LD, C_LD, lmjd);
  87.  
  88.     f_time (R_UT, C_UTV, mjd_hr(mjd));
  89.     f_date (R_UD, C_UD, mjd);
  90.  
  91.     (void) sprintf (buf, "%14.5f", jd);
  92.     (void) flog_log (R_JD, C_JDV, jd, buf);
  93.     f_string (R_JD, C_JDV, buf);
  94.  
  95.     now_lst (np, &tmp);
  96.     f_time (R_LST, C_LSTV, tmp);
  97.  
  98.     if (all) {
  99.         f_gangle (R_LAT, C_LATV, lat);
  100.         f_gangle (R_LONG, C_LONGV, -lng);    /* + west */
  101.  
  102.         tmp = height * 2.093e7;    /* want to see ft, not earth radii */
  103.         (void) sprintf (buf, "%5g ft", tmp);
  104.         (void) flog_log (R_HEIGHT, C_HEIGHTV, tmp, buf);
  105.         f_string (R_HEIGHT, C_HEIGHTV, buf);
  106.  
  107.         tmp = 9./5.*temp + 32.0;     /* want to see degrees F, not C */
  108.         (void) sprintf (buf, "%6g F", tmp);
  109.         (void) flog_log (R_TEMP, C_TEMPV, tmp, buf);
  110.         f_string (R_TEMP, C_TEMPV, buf);
  111.  
  112.         tmp = pressure / 33.86;    /* want to see in. Hg, not mBar */
  113.         (void) sprintf (buf, "%5.2f in", tmp);
  114.         (void) flog_log (R_PRES, C_PRESV, tmp, buf);
  115.         f_string (R_PRES, C_PRESV, buf);
  116.  
  117.         f_signtime (R_TZONE, C_TZONEV, tz);
  118.  
  119.         if (epoch == EOD)
  120.         f_string (R_EPOCH, C_EPOCHV, "(OfDate)");
  121.         else {
  122.         mjd_year (epoch, &tmp);
  123.         f_double (R_EPOCH, C_EPOCHV, "%8.1f", tmp);
  124.         }
  125.     }
  126.  
  127.     /* print the calendar for local day, if new month/year.  */
  128.     mm_calendar (np, all > 1);
  129. }
  130.  
  131. /* display dawn/dusk/length-of-night times.
  132.  */
  133. mm_twilight (np, force)
  134. Now *np;
  135. int force;
  136. {
  137.     double dusk, dawn;
  138.     double tmp;
  139.     int status;
  140.  
  141.     if (!twilight_cir (np, &dawn, &dusk, &status) && !force)
  142.         return;
  143.  
  144.     if (status != 0) {
  145.         f_blanks (R_DAWN, C_DAWNV, 5);
  146.         f_blanks (R_DUSK, C_DUSKV, 5);
  147.         f_string (R_LON, C_LONV, "-----");
  148.         return;
  149.     }
  150.  
  151.     f_mtime (R_DAWN, C_DAWNV, dawn);
  152.     f_mtime (R_DUSK, C_DUSKV, dusk);
  153.     tmp = dawn - dusk; range (&tmp, 24.0);
  154.     f_mtime (R_LON, C_LONV, tmp);
  155. }
  156.  
  157. mm_newcir (y)
  158. int y;
  159. {
  160.     static char ncmsg[] = "NEW CIRCUMSTANCES";
  161.     static char nomsg[] = "                 ";
  162.     static int last_y = -1;
  163.  
  164.     if (y != last_y) {
  165.         f_string (R_NEWCIR, C_NEWCIR, y ? ncmsg : nomsg);
  166.         last_y = y;
  167.     }
  168. }
  169.  
  170. static
  171. mm_calendar (np, force)
  172. Now *np;
  173. int force;
  174. {
  175.     static char *mnames[] = {
  176.         "January", "February", "March", "April", "May", "June",
  177.         "July", "August", "September", "October", "November", "December"
  178.     };
  179.     static int last_m, last_y;
  180.     static double last_tz = -100;
  181.     char str[64];
  182.     int m, y;
  183.     double d;
  184.     int f, nd;
  185.     int r;
  186.     double jd0;
  187.  
  188.     /* get local m/d/y. do nothing if still same month and not forced. */
  189.     mjd_cal (mjd_day(mjd-tz/24.0), &m, &d, &y);
  190.     if (m == last_m && y == last_y && tz == last_tz && !force)
  191.         return;
  192.     last_m = m;
  193.     last_y = y;
  194.     last_tz = tz;
  195.  
  196.     /* find day of week of first day of month */
  197.     cal_mjd (m, 1.0, y, &jd0);
  198.     mjd_dow (jd0, &f);
  199.     if (f < 0) {
  200.         /* can't figure it out - too hard before Gregorian */
  201.         int i;
  202.         for (i = 8; --i >= 0; )
  203.         f_string (R_CAL+i, C_CAL, "                    ");
  204.         return;
  205.     }
  206.  
  207.     /* print header */
  208.     f_blanks (R_CAL, C_CAL, 20);
  209.     (void) sprintf (str, "%s %4d", mnames[m-1], y);
  210.     f_string (R_CAL, C_CAL + (20 - (strlen(mnames[m-1]) + 5))/2, str);
  211.     f_string (R_CAL+1, C_CAL, "Su Mo Tu We Th Fr Sa");
  212.  
  213.     /* find number of days in this month */
  214.     mjd_dpm (jd0, &nd);
  215.  
  216.     /* print the calendar */
  217.     for (r = 0; r < 6; r++) {
  218.         char row[7*3+1], *rp = row;
  219.         int c;
  220.         for (c = 0; c < 7; c++) {
  221.         int i = r*7+c;
  222.         if (i < f || i >= f + nd)
  223.             (void) sprintf (rp, "   ");
  224.         else
  225.             (void) sprintf (rp, "%2d ", i-f+1);
  226.         rp += 3;
  227.         }
  228.         row[sizeof(row)-2] = '\0';    /* don't print last blank; causes wrap*/
  229.         f_string (R_CAL+2+r, C_CAL, row);
  230.     }
  231.  
  232.     /* over print the new and full moons for this month.
  233.      * TODO: don't really know which dates to use here (see moonnf())
  234.      *   so try several to be fairly safe. have to go back to 4/29/1988
  235.      *   to find the full moon on 5/1 for example.
  236.      */
  237.     mm_nfmoon (jd0-3, tz, m, f);
  238.     mm_nfmoon (jd0+15, tz, m, f);
  239. }
  240.  
  241. static
  242. mm_nfmoon (jd, tzone, m, f)
  243. double jd, tzone;
  244. int m, f;
  245. {
  246.     static char nm[] = "NM", fm[] = "FM";
  247.     double dm;
  248.     int mm, ym;
  249.     double jdn, jdf;
  250.     int di;
  251.  
  252.     moonnf (jd, &jdn, &jdf);
  253.     mjd_cal (jdn-tzone/24.0, &mm, &dm, &ym);
  254.     if (m == mm) {
  255.         di = dm + f - 1;
  256.         f_string (R_CAL+2+di/7, C_CAL+3*(di%7), nm);
  257.     }
  258.     mjd_cal (jdf-tzone/24.0, &mm, &dm, &ym);
  259.     if (m == mm) {
  260.         di = dm + f - 1;
  261.         f_string (R_CAL+2+di/7, C_CAL+3*(di%7), fm);
  262.     }
  263. }
  264.